//
//  OKDoctorInfor.m
//  ZLFastDoctor
//
//  Created by answer on 16/5/24.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "OKDoctorInfor.h"
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
#import <Masonry/Masonry.h>
#import "OKDoctorInfoModel.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface OKDoctorInfor ()
@property (strong, nonatomic) UIImageView *iconView;
@property (strong, nonatomic) UILabel *namelabel;
@property (strong, nonatomic) UILabel *doctortype;
@property (strong, nonatomic) UILabel *hospital;
@property (strong, nonatomic) UILabel *sickType;

@property (strong, nonatomic) UIButton *operation_count;
@property (strong, nonatomic) UIButton *flower;
@property (strong, nonatomic) UIButton *banner;
@end
@implementation OKDoctorInfor


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setModel:(OKDoctorInfoModel *)model {
    _model = model;
    
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.doctor_portrait] placeholderImage:[UIImage imageNamed:@"illness_img_person.png"] options:SDWebImageRetryFailed];
    self.namelabel.text = model.doctor_name;
    self.doctortype.text = model.doctor_title_name;
    self.hospital.text = model.hospital_name;
    self.sickType.text = [NSString stringWithFormat:@" -%@", model.department_name];
    
    [self.operation_count setTitle:model.operation_count forState:UIControlStateNormal];
    [self.flower setTitle:model.flower  forState:UIControlStateNormal];
    [self.banner setTitle:model.banner  forState:UIControlStateNormal];

}

- (void)setupUI {
    
    [self addSubview:self.iconView];
    [self addSubview:self.namelabel];
    [self addSubview:self.doctortype];
    [self addSubview:self.hospital];
    [self addSubview:self.sickType];
    
    [self addSubview:self.operation_count];
    [self addSubview:self.flower];
    [self addSubview:self.banner];
    
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(8);
        make.width.height.equalTo(65);
    }];
    
    [self.namelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.right).offset(10);
        make.top.equalTo(self.iconView);
    }];
    
    [self.doctortype makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView);
        make.left.equalTo(self.namelabel.right).offset(20);
    }];
    
    
    [self.hospital makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.right).offset(10);
        make.top.equalTo(self.namelabel.bottom).offset(5);
    }];
    
    [self.sickType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.hospital.right);
        make.top.equalTo(self.hospital);
    }];
    
    [self.operation_count makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.right).offset(10);
        make.bottom.equalTo(self.iconView.bottom).offset(5);
    }];
    
    [self.flower makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.operation_count.right).offset(40);
        make.bottom.equalTo(self.iconView.bottom).offset(5);
    }];
    
    [self.banner makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.flower.right).offset(40);
        make.bottom.equalTo(self.iconView.bottom).offset(5);
    }];
    
    [self makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.bottom.equalTo(self.iconView).offset(8);
    }];
}

- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc] init];
        UIImage *image = [UIImage imageNamed:@"illness_img_person.png"];
        _iconView.image = image;
        _iconView.layer.cornerRadius = 32;
        _iconView.clipsToBounds = YES;
    }
    return _iconView;
}

- (UILabel *)namelabel {
    if (_namelabel == nil) {
        _namelabel = [[UILabel alloc] init];
        _namelabel.text = @"肖";
    }
    return _namelabel;
}

- (UILabel *)doctortype {
    if (_doctortype == nil) {
        _doctortype = [[UILabel alloc] init];
        _doctortype.textColor = [UIColor lightGrayColor];
        _doctortype.text = @"主";
    }
    return _doctortype;
}

- (UILabel *)hospital {
    if (_hospital == nil) {
        _hospital = [[UILabel alloc] init];
        _hospital.textColor = [UIColor lightGrayColor];
        _hospital.font = [UIFont systemFontOfSize:14];
        _hospital.text = @"北";
    }
    return _hospital;
}

- (UILabel *)sickType {
    if (_sickType == nil) {
        _sickType = [[UILabel alloc] init];
        _sickType.textColor = [UIColor lightGrayColor];
        _sickType.font = [UIFont systemFontOfSize:14];
        _sickType.text = @"北";
    }
    return _sickType;
}

- (UIButton *)operation_count {
    if (_operation_count == nil) {
        _operation_count = [[UIButton alloc] init];
        [_operation_count setImage:[UIImage imageNamed:@"yuyueliang"] forState:UIControlStateNormal];
        [_operation_count setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [_operation_count setTitle:@"0" forState:UIControlStateNormal];
        [_operation_count addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _operation_count;
}

- (UIButton *)flower {
    if (_flower == nil) {
        _flower = [[UIButton alloc] init];
        [_flower setImage:[UIImage imageNamed:@"xianhua"] forState:UIControlStateNormal];
        [_flower setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [_flower setTitle:@"0" forState:UIControlStateNormal];
        [_flower addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _flower;
}

- (UIButton *)banner {
    if (_banner == nil) {
        _banner = [[UIButton alloc] init];
        [_banner setImage:[UIImage imageNamed:@"jinqi"] forState:UIControlStateNormal];
        [_banner setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [_banner setTitle:@"0" forState:UIControlStateNormal];
        [_banner addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _banner;
}

- (void)btnClick:(UIButton *)btn {
    
    btn.selected = !btn.selected;
    if (btn.selected == YES) {
        [btn setTitle:@"1" forState:UIControlStateSelected];
    } else {
        [btn setTitle:@"0" forState:UIControlStateNormal];
    }
    
}


@end









